import 'package:flutter/material.dart';

import 'colours.dart';

class MyCustomIndicator extends Decoration {
  @override
  BoxPainter createBoxPainter([VoidCallback? onChanged]) {
    return _MyCustomIndicatorPainter(this, onChanged);
  }
}

class _MyCustomIndicatorPainter extends BoxPainter {
  final MyCustomIndicator decoration;

  _MyCustomIndicatorPainter(this.decoration, VoidCallback? onChanged)
      : super(onChanged);

  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    final Paint paint = Paint()
      ..color = Colours.appMain // 可以修改为其他颜色
      ..style = PaintingStyle.fill;

    // 获取 TabBar 的宽高信息，调整为长度 20，高度 4
    const double width = 20.0;
    const double height = 4.0;

    // 创建一个带圆角的矩形
    final Rect rect = Rect.fromLTWH(
      offset.dx + (configuration.size!.width - width) / 2, // 中心对齐
      offset.dy + configuration.size!.height - height, // 设置在底部
      width, height,
    );

    final RRect rrect =
        RRect.fromRectAndRadius(rect, const Radius.circular(2.0));

    // 绘制圆角矩形
    canvas.drawRRect(rrect, paint);
  }
}
